
class UomUomFC(object):
    """
    Model:
        处理单位之间的逻辑

    Param:
        - env: odoo env

    Function:
        - convert_quantity: 单位换算并输出当前单位的数量
        - compute_price:同一单位情况下，计算特定数量的价格
    """

    def __init__(self, env):
        self.env = env


    def convert_quantity(self, from_uom, quantity, to_uom):
        """
        Convert quantity from one UoM to another.
        :param from_uom: 原单位(uom.uom)
        :param quantity: 原数量(float)
        :param to_uom: 现单位(uom.uom)
        :return: 现数量(float)
        """
        if from_uom.category_id != to_uom.category_id:

            # Convert the quantity to the reference unit of measure in the category
            reference_quantity = quantity * from_uom.factor

            # Convert the reference quantity to the target unit of measure
            target_quantity = reference_quantity / to_uom.factor

            return target_quantity
        else:
            return 0.0

    def compute_price(self, standard_num, standard_price, num):
        """
        同一单位情况下，计算特定数量的价格
        :param standard_num: 标准数量(float)
        :param standard_price: 标准价格(float)
        :param num: 特定的数量(float)
        :return: 特地数量的价格(float)
        """
        return (num / standard_num) * standard_price